home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / x2info / x2index.c < prev   
C/C++ Source or Header  |  1995-05-06  |  2KB  |  76 lines

  1. /*
  2. x2index for grepping x2ftp.oulu.fi:/pub/msdos/programming/00index.all
  3. Copyright (c) Jouni Miettunen 1995. All Rights Reserved.
  4.  
  5. I wrote it and have copyrighted to prevent anyone else from doing it.
  6. You may use it freely for both commercial and non-commercial purposes,
  7. but please do not distribute modified versions. If you update this or
  8. wish some changes or additions, please contact me (jon@stekt.oulu.fi).
  9.  
  10. 1.0     first release by Jouni Miettunen 6 May 1995
  11.  
  12. */
  13.  
  14. #include <ctype.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18.  
  19. int main(
  20.         int        argc,
  21.         char       **argv
  22.         )
  23. {
  24. char    *a,*c,*s,
  25.         workbuf[80],
  26.         dirbuf[80],
  27.         linebuf[128];
  28. FILE    *fp;
  29.  
  30. if (argc<2) exit(1);
  31. a = s = argv[1]; *dirbuf = 0;
  32.  
  33. /* case insensitive search: search string lowercase */
  34. while (*a) {
  35.         *a = ( isupper(*a) ? tolower(*a) : *a );
  36.         a++;
  37. }
  38.  
  39. fp = fopen("00index.all","rb");
  40. if (fp) {
  41.  
  42. while ((c = fgets(workbuf,80,fp)) != NULL) {
  43.        if (*c == '#') {
  44.                  memcpy(dirbuf,workbuf,80);  /* store directory name */
  45.                 continue;
  46.         }
  47.         memcpy(linebuf,workbuf,80);
  48.  
  49.         /* case insensitive search: index line lowercase */
  50.         a = c;
  51.         while (*a) {
  52.                 *a = ( isupper(*a) ? tolower(*a) : *a );
  53.                 a++;
  54.         }
  55.         
  56.         a = strstr(c,s);
  57.         if (c && a) {
  58.                 if (*dirbuf != 0) {
  59.                         puts("");
  60.                         fputs("x2ftp.oulu.fi:/pub/msdos/programming/",
  61.                               stdout);
  62.                         /* jump over ## Directory (TAB or many spaces) */
  63.                         a = dirbuf + 10;
  64.                         while (!isspace(*a)) a++;
  65.                         while (isspace(*a)) a++;
  66.                         fputs(a,stdout);
  67.                         *dirbuf = 0;
  68.                 }
  69.                 fputs(linebuf,stdout);
  70.         }
  71. }
  72. }
  73.  
  74. return (0);
  75. }
  76.